<?php
  require_once('tpl/header.php');
?>

<form>
	<input type="text" name="key">
	<input type="submit" value="搜索">
</form>
<?php 
    require_once('../system/loginCheck.php');
    require_once('../system/dbConn.php');
    connect();
    $sql="select * from videos join videotype on videos.tid=videotype.tid";
    if (isset($_GET["key"])) {
        $key=trim($_GET["key"]);
        $sql="select * from videos  join videotype on videos.tid=videotype.tid where videoname like '%{$key}%'";
    }
    $result=mysql_query($sql);
    $num=mysql_num_rows($result);
    if (!isset($_GET["page"])) {
        $page=1;
    }
    else{
        $page=$_GET["page"];
    }
    $rowsperpage=5;//每页有几名用户
    //一共分了多少页

    if ($num%$rowsperpage==0) {
        $totalpages=$num/$rowsperpage;
    }
    else
        $totalpages=ceil($num/$rowsperpage);
    //每页起始的用户
    $start=($page-1)*$rowsperpage;
    $sql1=$sql." limit $start,$rowsperpage";
    $result1=mysql_query($sql1);
    

 ?>
 <table class="table table-hover">
 	<tr>
 		<td>序号</td>
 		<td>视频名称</td>
 		<td>视频类型</td>
 		<td>海报图片</td>
 		<td>上传时间</td>
 		<td>操作</td>
 	</tr>
 	<?php 
    $i=1;
 	while ($row=mysql_fetch_assoc($result1)) {?>
        <tr>
        	<td><?php echo $row["vid"]; ?></td>
        	<td><?php echo $row["videoname"]; ?></td>
        	<td><?php echo $row["typename"]; ?></td>
        	<td><img src="../posters/<?php echo $row["pic"]; ?>" width="80px" height="80px" title="<?php echo $row["intro"]; ?>"></td>
        	<td><?php echo $row["uploaddate"]; ?></td>
        	<td><a href="videoEdit.php?vid=<?php echo $row["vid"]; ?>">修改</a>
        	<a href="doVideoDelete.php?vid=<?php echo $row["vid"]; ?>" onclick="return confirm('真的删除吗？')">删除</a></td>
        </tr>
<?php 
    $i++;
    }  ?>
 	
 	 </table>
     <h3 align="center">
        <?php 
            echo "共有".$num."名用户"."&nbsp"."共分".$totalpages."页"."&nbsp";
            if ($page==1) {
                echo "首页"."&nbsp";
            }
            else
                echo "<a href=?page=1>首页</a>"."&nbsp";
            if ($page==1) {
                echo "上一页"."&nbsp";
            }
            else
                echo "<a href=?page=".($page-1).">上一页</a>"."&nbsp";
            for ($i=1; $i<=$totalpages ; $i++) {
                echo "<a href=?page=$i>第".$i."页</a>"."&nbsp";
            }
            if ($page==$totalpages) {
                echo "尾页"."&nbsp";
            }
            else
                echo "<a href=?page=$totalpages>尾页</a>"."&nbsp";
            if ($page==$totalpages) {
                echo "下一页"."&nbsp";
            }
            else
                echo "<a href=?page=".($page+1).">下一页</a>"."&nbsp";
        ?>
    </h3>

   


<?php
  require_once('tpl/footer.php');
?>